import 'package:htxd_flutter_mapbox_sdk/mapbox/util/uuid_util.dart';

import 'point_entity.dart';

class LandInfoEntity {
  String? isFLow; //是否流转
  String? landCertificate; // 地块确权编号
  String? landName; // 地块确权名称
  String? confirmationArea; // 确权面积，输入的面积
  String? realityArea; // 真实面积
  String? userName; // 被保险人名称
  String? idCard; // 被保险人身份证号码
  String? east; //东
  String? south; //南
  String? west; //西
  String? north; //北
  String? perimeter; // 周长
  List<PointEntity>? path; // 地块边界
  String? uuid; // 地块的唯一标识 uuid
  int? state; // 地块的状态 0 没有修改 1 修改 2 删除 3 新增
  PointEntity? center; // 中心点
  String? picUrl; // 图片url 地址

  LandInfoEntity(
      {this.isFLow = "是",
      this.landCertificate,
      this.landName,
      this.confirmationArea,
      this.realityArea,
      this.userName,
      this.idCard,
      this.east,
      this.south,
      this.west,
      this.north,
      this.perimeter,
      this.path,
      this.uuid,
      this.state,
      this.center,
      this.picUrl}) {
    uuid ??= UuidUtil.instance.getUuid();
  }

  LandInfoEntity.fromJson(dynamic json) {
    isFLow = json['isFLow'] ?? "否";
    landCertificate = json['landCertificate'];
    landName = json['landName'];
    confirmationArea = json['confirmationArea'];
    realityArea = json['realityArea'];
    userName = json['userName'];
    idCard = json['idCard'];
    east = json['east'];
    south = json['south'];
    west = json['west'];
    north = json['north'];
    perimeter = json['perimeter'];
    if (json['path'] != null) {
      path = [];
      json['path'].forEach((v) {
        path?.add(PointEntity.fromJson(v));
      });
    }
    uuid = json['uuid'] ?? UuidUtil.instance.getUuid();
    state = json["state"] ?? 0;
    if (json["center"] != null) {
      center = PointEntity.fromJson(json["center"]);
    }
    picUrl = json["picUrl"];
  }

  LandInfoEntity copyWith(
          {String? isFLow,
          String? landCertificate,
          String? landName,
          String? confirmationArea,
          String? realityArea,
          String? userName,
          String? idCard,
          String? east,
          String? south,
          String? west,
          String? north,
          String? perimeter,
          List<PointEntity>? path,
          String? uuid,
          int? state,
          PointEntity? center,
          String? picUrl}) =>
      LandInfoEntity(
          isFLow: isFLow ?? this.isFLow,
          landCertificate: landCertificate ?? this.landCertificate,
          landName: landName ?? this.landName,
          confirmationArea: confirmationArea ?? this.confirmationArea,
          realityArea: realityArea ?? this.realityArea,
          userName: userName ?? this.userName,
          idCard: idCard ?? this.idCard,
          east: east ?? this.east,
          south: south ?? this.south,
          west: west ?? this.west,
          north: north ?? this.north,
          perimeter: perimeter ?? this.perimeter,
          path: path ?? this.path,
          uuid: uuid ?? this.uuid,
          state: state ?? this.state,
          center: center ?? this.center,
          picUrl: picUrl ?? this.picUrl);

  Map<String, dynamic> toJson() {
    final map = <String, dynamic>{};
    map['isFLow'] = isFLow;
    map['landCertificate'] = landCertificate;
    map['landName'] = landName;
    map['confirmationArea'] = confirmationArea;
    map['realityArea'] = realityArea;
    map['userName'] = userName;
    map['idCard'] = idCard;
    map['east'] = east;
    map['south'] = south;
    map['west'] = west;
    map['north'] = north;
    map['perimeter'] = perimeter;
    if (path != null) {
      map['path'] = path?.map((v) => v.toJson()).toList();
    }
    map['uuid'] = uuid;
    map['state'] = state;
    map['picUrl'] = picUrl;
    if (center != null) {
      map['center'] = center?.toJson();
    }
    return map;
  }
}
